//
//  RootViewController.m
//  豆瓣综合网页
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "MyTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "Root2ViewController.h"
@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) NSMutableDictionary *newDic;
@end
@implementation RootViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)dealloc
{
    [_newDic release];
    [_tableView release];
    [_arr release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    _tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_tableView];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    self.navigationItem.title =@"活动";
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:86/255.0 green:137/255.0 blue:156/255.0 alpha:1];
    [_tableView release];
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
    
    self.arr = [NSMutableArray arrayWithContentsOfFile:path];

//    NSLog(@"%@", _arr);
    self.navigationController.navigationBar.backgroundColor = [UIColor colorWithRed:86/255.0 green:137/255.0 blue:156/255.0 alpha:1];
    self.newDic = [NSMutableDictionary dictionary];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    NSString *str = _arr[indexPath.row][@"image"];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:str]];
    cell.titleLabel.text = _arr[indexPath.row][@"title"];
    
    cell.timeLabel.text = [NSString stringWithFormat:@"%@--%@", [_arr[indexPath.row][@"begin_time"] substringWithRange:NSMakeRange(5, 11)], [_arr[indexPath.row][@"end_time"] substringWithRange:NSMakeRange(5, 11)]];
    cell.addLabel.text = _arr[indexPath.row][@"address"];
    cell.typeLabel.text = _arr[indexPath.row][@"category_name"];
    
    cell.hobbyLabel11.text = @"感兴趣";
    cell.hobbyLabel11.font = [UIFont systemFontOfSize:15];
    cell.hobbyLabel22.text = [NSString stringWithFormat:@"%@", [_arr [indexPath.row]objectForKey:@"wisher_count"]];
    cell.hobbyLabel22.textColor = [UIColor redColor];
    
    cell.joinLabel11.text = @"参加：";
    cell.joinLabel11.font = [UIFont systemFontOfSize:15];
    cell.joinLabel22.text = [NSString stringWithFormat:@"%@", [_arr [indexPath.row] objectForKey:@"participant_count"]];
    cell.joinLabel22.textColor = [UIColor redColor];
    
    return  cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 220;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    Root2ViewController *root2VC = [[Root2ViewController alloc] init];
    root2VC.arr = _arr;
    root2VC.Dic = [NSMutableDictionary dictionaryWithDictionary:_newDic];
    root2VC.block = ^(NSString *str1) {
        [_newDic setObject:@"已收藏" forKey:str1];
    };
    root2VC.indexPath = indexPath;
    [self.navigationController pushViewController:root2VC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
